#include<iostream>
using namespace std;
typedef long long LL;
LL y,z,ret=1e15;//注意ret给0x3f3f3f3f太小了 
LL Min(LL x,LL y)
{
	if(x<y) return x;
	else return y;
}
LL Abs(LL x)
{
	if(x<0) return -x;
	else return x;
}

int main()
{
	cin>>y>>z;
	for(LL i=100000;i<=999999;i++)
	{
		LL x=i*1000000+y;
		LL c=x-z;
		ret=Min(ret,Abs(c));	
	}      
	cout<<ret<<endl;
	return 0;
}